# -*- coding: utf-8 -*-
import json
import scrapy


class XicidailiSpider(scrapy.Spider):
    name = "xicidaili"
    allowed_domains = ["www.xicidaili.com"]
    start_urls = ['http://api.xicidaili.com/']

    def parse(self, response):
        print response.body
        arr = response.body.split('\r\n')

        output = {'arr': []}
        for address in arr:
            item = {'ip_port': address, 'user_pass': ''}
            output['arr'].append(item)

        fo = open("proxy_list.txt", "w")
        data = json.dumps(output)
        fo.write(data)
        fo.close()
